<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller {

	public function __construct()
	{
		parent::__construct();
		$this->load->database();
		$this->load->helper('url');
		$this->load->library('grocery_CRUD');
	}

	public function _student_output($output = null)
	{
		$this->load->view('home.php',$output);
	}

	public function Home()
	{
		$output = $this->grocery_crud->render();
		$this->_student_output($output);
	}

	public function index()
	{

		if($this->session->userdata('logged_in'))
   		{
     		$session_data = $this->session->userdata('logged_in');
     		$data['username'] = $session_data['username'];
     		//$this->load->view('home_view', $data);
			//$this->_student_output((object)array('output' => '' , 'js_files' => array() , 'css_files' => array()));
			$crud = new grocery_CRUD();
			$crud->set_table('student');
			$crud->columns('Std_id','Std_name','Std_lastname','Std_age','Std_sex','Std_townhome');
			$crud->display_as('Std_id','Student ID')
				 ->display_as('Std_name','First Name')
				 ->display_as('Std_lastname','Last Name')
				 ->display_as('Std_age','Age')
				 ->display_as('Std_sex','Sex')
				 ->display_as('Std_townhome','Townhome');
			$crud->required_fields('Std_id','Std_name','Std_lastname');
			$crud->field_type('Std_sex','dropdown',
            		array('male' => 'Male', 'female' => 'Female'));
			$crud->set_subject('Student');

			$output = $crud->render();

			$this->_student_output($output);
   }
   else
   {
     //If no session, redirect to login page
     redirect('login', 'refresh');
   }
}


	function logout()
 {
   $this->session->unset_userdata('logged_in');
   redirect('home', 'refresh');
 }

}